<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class LinksController extends Controller
{
    //友情链接添加页
    public function getAdd() 
    {
        return view('/webadmin.links.add');
    }

    //友情链接添加操作
    public function postInsert(Request $request)
    {
        //提取参数
        $data = $request -> except(['_token']);
        //执行数据库插入
        $res = DB::table('links')->insert($data);
        if($res) {
            return redirect('/admin/links');
        }else{
            return back();
        }
    }

    //友情链接列表显示页
    public function getIndex()
    {
        $res = DB::table('links') -> get();
        return view('/webadmin.links.index', [
            'links' => $res
            ]);
    }

    //友情链接删除
    public function getDelete(Request $request)
    {
        //获取id
        $id = $request->input('id');
        //删除当前的品牌
        $res = DB::table('links')->where('id','=',$id)->delete();
        if($res) {
            return back()->with('info','删除成功');
        }else{
            return back()->with('info','删除失败');
        }
    }
}

